package com.mind.invoice.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.mind.common.annotation.Log;
import com.mind.common.web.controller.BaseController;
import com.mind.common.core.domain.AjaxResult;
import com.mind.common.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.mind.invoice.domain.AjReport;
import com.mind.invoice.service.IAjReportService;
import com.mind.common.utils.poi.ExcelUtil;
import com.mind.common.web.page.TableDataInfo;

/**
 * 报告Controller
 * 
 * @author today
 * @date 2025-04-25
 */
@RestController
@RequestMapping("/invoice/report")
@Tag(name = "报告管理", description = "报告管理")
public class AjReportController extends BaseController
{
    @Autowired
    private IAjReportService ajReportService;

    /**
     * 查询报告列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:report:list')")
    @GetMapping("/list")
    @Operation(summary = "查询报告列表", description = "查询报告列表")
    public TableDataInfo list(AjReport ajReport)
    {
        startPage();
        List<AjReport> list = ajReportService.selectAjReportList(ajReport);
        return getDataTable(list);
    }

    /**
     * 导出报告列表
     */
    @PreAuthorize("@ss.hasPermi('invoice:report:export')")
    @Log(title = "报告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @Operation(summary = "导出报告列表", description = "查询报告列表")
    public void export(HttpServletResponse response, AjReport ajReport)
    {
        List<AjReport> list = ajReportService.selectAjReportList(ajReport);
        ExcelUtil<AjReport> util = new ExcelUtil<AjReport>(AjReport.class);
        util.exportExcel(response, list, "报告数据");
    }

    /**
     * 获取报告详细信息
     */
    @PreAuthorize("@ss.hasPermi('invoice:report:query')")
    @GetMapping(value = "/{id}")
    @Operation(summary = "获取报告详细信息", description = "获取报告详细信息")
    public AjaxResult getInfo(@Parameter(description ="报告Id",required=true) @PathVariable("id") Long id)
    {
        return success(ajReportService.selectAjReportById(id));
    }

    /**
     * 新增报告
     */
    @PreAuthorize("@ss.hasPermi('invoice:report:add')")
    @Log(title = "报告", businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增报告", description = "新增报告")
    public AjaxResult add(@RequestBody AjReport ajReport)
    {
        return toAjax(ajReportService.insertAjReport(ajReport));
    }

    /**
     * 修改报告
     */
    @PreAuthorize("@ss.hasPermi('invoice:report:edit')")
    @Log(title = "报告", businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改报告", description = "修改报告")
    public AjaxResult edit(@RequestBody AjReport ajReport)
    {
        return toAjax(ajReportService.updateAjReport(ajReport));
    }

    /**
     * 删除报告
     */
    @PreAuthorize("@ss.hasPermi('invoice:report:remove')")
    @Log(title = "报告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @Operation(summary = "删除报告", description = "删除报告")
    public AjaxResult remove(@Parameter(description ="报告Id",required=true) @PathVariable Long[] ids)
    {
        return toAjax(ajReportService.deleteAjReportByIds(ids));
    }
}
